package com.base.sort;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * this is a class demo.
 *
 * @author pretty_boy
 * @date 2018/9/27 10:18
 */
public class Java8Test {
    public static void main(String[] args) {
        List<String> list = new ArrayList<String>();

        list.add("Google");
        list.add("Baidu");
        list.add("Taobao");
        list.add("Sina");
        list.add("Tianmao");

        //java8排序
        sortList(list);
        System.out.println("java8:" + list);
        //Java7排序
        sortByJava7(list);
        System.out.println(list.toString());
    }

    private static void sortByJava7(List<String> list) {
        Collections.sort(list, new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return o1.compareTo(o2);
            }
        });
        Collections.sort(list);
    }

    private static void sortList(List<String> list) {

        Collections.sort(list, String::compareTo);
    }


}
